package com.daily.DailyStudy.kafka.consumer;

import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Component;

import java.util.Optional;

@Component
public class ConsumerTest {

    @Autowired
    KafkaTemplate kafkaTemplate;

    @KafkaListener(topics = "user_test")
    public void comsumer(ConsumerRecord consumerRecord){
        Optional<Object> kafaMessage = Optional.ofNullable(consumerRecord.value());
        if(kafaMessage.isPresent()){
            Object o = kafaMessage.get();
            System.out.println("kafka消费数据："+o);
        }
    }

}
